import 'package:flutter/material.dart';

import '../../widgets/dashed_line.dart';
import '../../widgets/star_rating.dart';
import '../../widgets/image_widget.dart';
import '../../model/home_model.dart';

class HYBuildContent extends StatelessWidget {
  final MovieItem movie;

  HYBuildContent(this.movie);

  @override
  Widget build(BuildContext context) {
    return Row(
      crossAxisAlignment: CrossAxisAlignment.start,
      children: [
        buildContentImage(),
        SizedBox(width: 8),
        Expanded(
            child: IntrinsicHeight(
          child: Row(
            children: [
              buildContentInfo(),
              SizedBox(width: 8),
              buildContentLine(),
              SizedBox(width: 8),
              buildContentWish()
            ],
          ),
        ))
      ],
    );
  }

  //2.1 内容的图片
  Widget buildContentImage() {
    return ClipRRect(
      borderRadius: BorderRadius.circular(5),
      child: HYImageWidget(url: movie.imageURL, h: 150),
    );
  }

  //2.2 内容的信息
  Widget buildContentInfo() {
    return Expanded(
      child: Column(
        crossAxisAlignment: CrossAxisAlignment.start,
        children: [
          buildContentInfoTitle(),
          SizedBox(height: 8),
          buildContentInfoRate(),
          SizedBox(height: 8),
          buildContentInfoDesc()
        ],
      ),
    );
  }

  // 2.2.1 电影标题
  Widget buildContentInfoTitle() {
    return Text.rich(
      TextSpan(children: [
        WidgetSpan(
            child: Icon(
              Icons.play_circle_outline,
              color: Colors.redAccent,
              size: 24,
            ),
            baseline: TextBaseline.ideographic,
            alignment: PlaceholderAlignment.middle),
        ...movie.title.runes.map((e) {
          return WidgetSpan(
              child: Text(new String.fromCharCode(e),
                  style: TextStyle(fontSize: 20, fontWeight: FontWeight.bold)),
              alignment: PlaceholderAlignment.middle);
        }),
        // TextSpan(
        //     text: movie.title,
        //     style: TextStyle(fontSize: 20, fontWeight: FontWeight.bold)),
        WidgetSpan(
          child: Text('(${movie.playDate})',
              style: TextStyle(fontSize: 18, color: Colors.grey)),
        )
      ]),
    );
  }

  // 2.2.2 电影评分
  Widget buildContentInfoRate() {
    return FittedBox(
      child: Row(
        children: [
          HYStarRating(
            rating: movie.rating,
            size: 20,
            selectedColor: Colors.orange,
          ),
          SizedBox(width: 6),
          Text(
            '${movie.rating}',
            style: TextStyle(fontSize: 16),
          )
        ],
      ),
    );
  }

  // 2.2.3 影片导演和演员信息
  Widget buildContentInfoDesc() {
    // 1.字符串拼接
    final genresString = movie.genres.join(' ');
    final directorString = movie.director.name;
    final actorString = movie.casts.map((e) => e.name).toList().join(' ');
    return Expanded(
      child: Text(
        '$genresString / $directorString / $actorString',
        style: TextStyle(fontSize: 16),
        maxLines: 2,
        overflow: TextOverflow.ellipsis,
      ),
    );
  }

  // 2.3内容的虚线
  Widget buildContentLine() {
    return Container(
        width: 1,
        child: HYDashedLine(
          axis: Axis.vertical,
          dashedWidth: .5,
          dashedHeight: 6,
          count: 12,
        ));
  }

  // 2.4 内容的想看
  Widget buildContentWish() {
    return Column(
      // mainAxisAlignment: MainAxisAlignment.start,
      children: [
        SizedBox(height: 20),
        Image.asset('assets/images/home/wish.png', width: 30),
        SizedBox(height: 5),
        Text('想看',
            style: TextStyle(
                fontSize: 16, color: Color.fromARGB(255, 235, 170, 60)))
      ],
    );
  }
}
